package {
	import alternativa.engine3d.core.Mesh;
	import alternativa.types.Point3D;
	import alternativa.types.Texture;
	import alternativa.engine3d.materials.FillMaterial;
	import alternativa.engine3d.materials.TextureMaterial;
	import flash.display.BlendMode;
	import flash.geom.Point;
	

	public class Skybox extends Mesh {

		[Embed(source="skybox/skybox_s.jpg")] private static const bmpSkybox_s:Class;
		private static const skybox_s:Texture = new Texture(new bmpSkybox_s().bitmapData, "skybox_s.jpg");
		[Embed(source="skybox/skybox_w.jpg")] private static const bmpSkybox_w:Class;
		private static const skybox_w:Texture = new Texture(new bmpSkybox_w().bitmapData, "skybox_w.jpg");
		[Embed(source="skybox/skybox_e.jpg")] private static const bmpSkybox_e:Class;
		private static const skybox_e:Texture = new Texture(new bmpSkybox_e().bitmapData, "skybox_e.jpg");
		[Embed(source="skybox/skybox_n.jpg")] private static const bmpSkybox_n:Class;
		private static const skybox_n:Texture = new Texture(new bmpSkybox_n().bitmapData, "skybox_n.jpg");
		[Embed(source="skybox/skybox_u.jpg")] private static const bmpSkybox_u:Class;
		private static const skybox_u:Texture = new Texture(new bmpSkybox_u().bitmapData, "skybox_u.jpg");
		[Embed(source="skybox/skybox_d.jpg")] private static const bmpSkybox_d:Class;
		private static const skybox_d:Texture = new Texture(new bmpSkybox_d().bitmapData, "skybox_d.jpg");

		public function Skybox() {
			super("Skybox");

//			coords = new Point3D(1823, 392, -8984);

			createVertex(7000, -7000, -0.1, 1);
			createVertex(-7000, 7000, -0.1, 2);
			createVertex(7000, -7000, 7000, 11);
			createVertex(-7000, -7000, -0.1, 13);
			createVertex(7000, 7000, -0.1, 15);
			createVertex(7000, 7000, 7000, 17);
			createVertex(-7000, 7000, 7000, 18);
			createVertex(-7000, -7000, 7000, 24);

			createFace([11, 17, 15, 1], 12);
			setUVsToFace(new Point(0, 1), new Point(1, 1), new Point(1, 0), 12);
			createFace([2, 15, 17, 18], 13);
			setUVsToFace(new Point(1, 0), new Point(0, 0), new Point(0, 1), 13);
			createFace([1, 13, 24, 11], 14);
			setUVsToFace(new Point(1, 0), new Point(0, 0), new Point(0, 1), 14);
			createFace([11, 24, 18, 17], 15);
			setUVsToFace(new Point(1, 0), new Point(0, 0), new Point(0, 1), 15);
			createFace([13, 2, 18, 24], 16);
			setUVsToFace(new Point(1, 0), new Point(0, 0), new Point(0, 1), 16);
			createFace([1, 15, 2, 13], 17);
			setUVsToFace(new Point(0, 0), new Point(0, 10), new Point(10, 10), 17);

			
			// nord
			createSurface([14], "skybox_n");
			var materialN:TextureMaterial = new TextureMaterial(skybox_n, 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			setMaterialToSurface(materialN, "skybox_n");
			//est
			createSurface([12], "skybox_e");
			var materialE:TextureMaterial = new TextureMaterial(skybox_e, 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			setMaterialToSurface(materialE, "skybox_e");
			// ouest
			createSurface([16], "skybox_w");
			var materialW:TextureMaterial = new TextureMaterial(skybox_w, 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3);
			setMaterialToSurface(materialW, "skybox_w");
			// sud
			createSurface([13], "skybox_s");
			var materialS:TextureMaterial = new TextureMaterial(skybox_s, 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3); 
			setMaterialToSurface(materialS, "skybox_s");
			// en haut
			createSurface([15], "skybox_u");
			var materialU:TextureMaterial = new TextureMaterial(skybox_u, 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3); 
			setMaterialToSurface(materialU, "skybox_u");
			// en bas
			createSurface([17], "skybox_d");
			var materialD:TextureMaterial = new TextureMaterial(skybox_d, 1, true, true, BlendMode.NORMAL, -1, 0x000000, 3); 
			setMaterialToSurface(materialD, "skybox_d");
		}
	}
}